
#include <QtWidgets>
#include "CaptureIMGWidget.h"

CaptureIMGWidget::CaptureIMGWidget(QString fileName, QWidget* parent)
	:QWidget(parent)
	,IMGFileName(fileName)
	, img(NULL)
{
	ui.setupUi(this);
	setAutoFillBackground(true);
	//setAttribute(Qt::WA_TranslucentBackground, true);
	//setWindowFlags(Qt::WindowStaysOnTopHint | Qt::WindowCloseButtonHint);
	this->setAttribute(Qt::WA_DeleteOnClose, 1);

	QTimer* closeTimer = new QTimer(this);
	closeTimer->setInterval(5000);
	connect(closeTimer, SIGNAL(timeout()), this, SLOT(close()));

	QTimer::singleShot(500, this, SLOT(LoadImg()));

	
//	setFocusPolicy(Qt::NoFocus);
	ui.label_Text->setStyleSheet("color: rgb(0, 255, 255);");


	ui.label_Text->setWordWrap(true);
	ui.label_Text->setTextFormat(Qt::RichText);
	ui.label_Text->setText("<a href=\"" + fileName+ "\">" + QFileInfo(fileName).fileName());
	connect(ui.label_Text, SIGNAL(linkActivated(const QString &)), this,SLOT(onTextLinkActivated(const QString &)));

	closeTimer->start();

}

void CaptureIMGWidget::onTextLinkActivated(const QString & url)
{
	QDesktopServices::openUrl(QUrl::fromLocalFile(url));
}

void CaptureIMGWidget::LoadImg()
{

	img = new QImage;
	img->load(IMGFileName);
	ui.label_Image->setPixmap(QPixmap::fromImage(img->scaled(ui.label_Image->size(), Qt::IgnoreAspectRatio)));
}

CaptureIMGWidget::~CaptureIMGWidget()
{
	if (img)
		delete img;
}

